package com.onenine.app.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.onenine.app.R;
import com.onenine.app.model.ReplyMsgItem;
import com.onenine.app.utils.DataType;
import com.onenine.app.utils.GlideUtils;
import com.onenine.app.view.NVoiceBar;
import com.onenine.chat.util.SimpleCommonUtils;
import com.onenine.common.util.ApUtils;
import com.onenine.common.util.ScreenUtils;

public class ReplyMsgAdapter extends BaseQuickAdapter<ReplyMsgItem, BaseViewHolder> {

    private int maxWidth;

    public ReplyMsgAdapter() {
        super(R.layout.layout_msg_reply_item);
        maxWidth = ScreenUtils.getScreenWidth() - 2 * ApUtils.getApp()
                .getResources().getDimensionPixelOffset(R.dimen.dp25);
    }

    @Override
    protected void convert(final BaseViewHolder holder, final ReplyMsgItem msgItem) {
        GlideUtils.loadSrcImage(mContext, holder.getView(R.id.niv_avatar), msgItem.getPhoto());
        holder.setText(R.id.tv_name, msgItem.getNickName()).setText(R.id.tv_date, msgItem.getDate());
        TextView tvComment = holder.getView(R.id.tv_content);
        NVoiceBar nVoiceBar = holder.getView(R.id.nv_voice);
        TextView tvContent = holder.getView(R.id.tv_src_content);
        ImageView ivContent = holder.getView(R.id.iv_src_content);
        if (msgItem.getcType() == DataType.COMMENT_VOICE_TYPE) {
            //语音评论
            tvComment.setVisibility(View.GONE);
            nVoiceBar.setVisibility(View.VISIBLE);
            nVoiceBar.setVoiceLengthVisible(false);
            nVoiceBar.setSexStyle(msgItem.getSex(), true);
            nVoiceBar.setData(msgItem.getDescriptionContent(), 0f);
        } else {
            //文本评论
            tvComment.setVisibility(View.VISIBLE);
            nVoiceBar.setVisibility(View.GONE);
            SimpleCommonUtils.spannableEmoticonFilter(tvComment
                    , msgItem.getDescriptionContent());
        }
        if (msgItem.getmType() == DataType.MSG_TEXT_TYPE) {
            //文字
            tvContent.setVisibility(View.VISIBLE);
            tvContent.setText(msgItem.getRemark());
            ivContent.setVisibility(View.GONE);
        } else {
            //图片或视频
            ivContent.setVisibility(View.VISIBLE);
            tvContent.setVisibility(View.GONE);
            GlideUtils.loadRoundImageFitWidth(mContext, ivContent, msgItem.getRemark(), maxWidth);
        }
    }

}
